package com.xiaocikuai.smallchunks.service.Advertise;

import com.xiaocikuai.smallchunks.entity.Advertise.Advertise;
import com.xiaocikuai.smallchunks.file.PutObject004;
import com.xiaocikuai.smallchunks.mapper.Advertise.AdvertiseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Date;

@Service
public class AdvertiseService {
    @Autowired
    private AdvertiseMapper advertiseMapper;

    @Autowired
    private PutObject004 putObject004;
    public void addAdvertise(MultipartFile file, String theme, String url, Date time,Integer platform) {
        Advertise advertise=new Advertise();
        advertise.setImage(putObject004.uploadFile(file, "ad"));
       // System.out.println(putObject004.uploadFile(file, "ad"));
        advertise.setTheme(theme);
        advertise.setTime(time);
        advertise.setLinkWeb(url);
        advertise.setPlatform(platform);
        advertiseMapper.add(advertise);
   }

    public void DeleteAdvertise(Advertise advertise) {

        advertiseMapper.delete(advertise);
    }

    public void UpdateAdvertise(MultipartFile file, String theme, String url, Date time,Integer platform) {
        {
        Advertise advertise=new Advertise();

        if(file!=null)
        {
            advertise.setImage(putObject004.uploadFile(file, "ad"));
        }
        advertise.setTheme(theme);
        advertise.setTime(time);
        advertise.setLinkWeb(url);
        advertise.setPlatform(platform);
        advertiseMapper.update(advertise);
        }
    }
}
